package com.lx.onbording.vshe.testassignment.core.component;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.lx.onbording.vshe.testassignment.core.domain.Order;
import com.lx.onbording.vshe.testassignment.core.domain.OrderItem;

@Component
public class OrderSplitter {
	
	public List<Order> splitOrder(Order order) {
		List<Order> result = new ArrayList<Order>();
		
		if (order.getOrderItems().size() <= 1) {
			result.add(order);
			return result;
		}
		
		for (OrderItem item: order.getOrderItems()) {
			Order splittedOrder = new Order();
			splittedOrder.setDate(order.getDate());
			splittedOrder.getOrderItems().add(item);
			result.add(splittedOrder);
		}
		
		return result;
	}
}
